﻿@using System.Globalization

<EditForm Model="@TestModel" OnValidSubmit="@HandleOnValidSubmit" OnInvalidSubmit="@HandleOnInvalidSubmit">
    <DataAnnotationsValidator />

    <BitDatePicker IsEnabled="IsEnabled"
                   Culture="Culture"
                   @bind-Value="@TestModel.Value"
                   Placeholder="@Placeholder"
                   GoToTodayTitle="@GoToToday"
                   @bind-IsOpen="IsOpen"
                   OnClick="HandleOnClick"
                   OnChange="HandleSelectDate">
        <LabelTemplate>
            @LabelTemplate
        </LabelTemplate>
    </BitDatePicker>

</EditForm>

@code {
    [Parameter] public bool IsEnabled { get; set; }
    [Parameter] public CultureInfo Culture { get; set; } = CultureInfo.CurrentUICulture;
    [Parameter] public BitDatePickerTestModel TestModel { get; set; } = new();
    [Parameter] public DateTimeOffset? Value { get; set; }
    [Parameter] public string? Placeholder { get; set; }
    [Parameter] public string? GoToToday { get; set; }
    [Parameter] public bool IsOpen { get; set; }
    [Parameter] public RenderFragment? LabelTemplate { get; set; }

    public int ClickedValue { get; set; }
    public int SelectedDateValue { get; set; }
    public int ValidCount { get; set; }
    public int InvalidCount { get; set; }

    public void HandleOnClick()
    {
        ClickedValue++;
    }

    public void HandleSelectDate(DateTimeOffset? value)
    {
        SelectedDateValue++;
    }

    private void HandleOnValidSubmit()
    {
        ValidCount++;
    }

    private void HandleOnInvalidSubmit()
    {
        InvalidCount++;
    }
}
